/*****************************************************************************
 * plum_mbedtls_test.c
 *
 * Copyright (C) 2020 Jeasonvor 1101627719@qq.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 ****************************************************************************/

/*****************************************************************************
 * Included Files
 ****************************************************************************/
#include "plum_api.h"
/*****************************************************************************
 * Trace Definitions
 ****************************************************************************/
#define LOG_RUN_LEVEL LOG_LEVEL_DEBUG
#define LOG_MODULE    "mbedtls.test"
#include "thirdparty/log/log.h"
/*****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/

/*****************************************************************************
 * Private Types
 ****************************************************************************/

/*****************************************************************************
 * Private Function Prototypes
 ****************************************************************************/

/*****************************************************************************
 * Private Data
 ****************************************************************************/

/*****************************************************************************
 * Public Data
 ****************************************************************************/

/*****************************************************************************
 * Private Functions
 ****************************************************************************/

/*****************************************************************************
 * Public Functions
 ****************************************************************************/

int main()
{
    // varint(pass)
    {
        unsigned long long number = 23113293191329;
        char*              str    = calloc(10, sizeof(char));
        unsigned char      bts;

        bts = plum_cal_mbedtls_varint_encode(str, 10, number);
        LOG_D("varint encode bts : %d", bts);

        unsigned long long varint = 0;
        int len = plum_cal_mbedtls_varint_decode(str, bts, &varint);
        LOG_D("varint decode : %lld,len : %d", varint, len);
        free(str);
    }

    // md5(pass)
    {
        char buf[]   = "this is a md5 test string";
        char md5[33] = {0};
        plum_cal_mbedtls_md5_string(buf, sizeof(buf) - 1, md5);
        LOG_D("md5 : %s", md5);
    }

    // base64
    {
        // pass
        unsigned char num[]      = "this is a test";
        char          base64[64] = {0};
        unsigned int  outlen     = sizeof(base64);
        int rc = plum_cal_mbedtls_base64_encode(num, sizeof(num) - 1, base64,
                                                &outlen);
        LOG_D("base64 encode rc = %d: %s", rc, base64);

        // unpass
        char         out[64] = {0};
        unsigned int len     = sizeof(out);
        plum_cal_mbedtls_base64_decode(base64, outlen, out, &len);
        LOG_D("base64 decode rc = %d: %s", rc, out);
        LOG_DHEX("deocde :", out, len);
    }

    // aes
    {
    }

    return 0;
}

/****************************************************************************/
/*                                                                          */
/*  End of file.                                                            */
/*                                                                          */
/****************************************************************************/
